package com.qyhl.shop.shop.rush.detail.order;

import com.qyhl.shop.common.ShopUrl;
import com.qyhl.webtv.basiclib.utils.network.EasyHttp;
import com.qyhl.webtv.basiclib.utils.network.callback.SimpleCallBack;
import com.qyhl.webtv.basiclib.utils.network.exception.ApiException;
import com.qyhl.webtv.commonlib.common.CommonUtils;
import com.qyhl.webtv.commonlib.entity.shop.ShopGiftDetailBean;
import com.qyhl.webtv.commonlib.entity.shop.ShopPayResultBean;

public class ShopOrderModel implements ShopOrderContract.ShopOrderModel {
    private ShopOrderPresenter mPresenter;

    public ShopOrderModel(ShopOrderPresenter mPresenter) {
        this.mPresenter = mPresenter;
    }

    @Override
    public void getDetail(int userGiftId) {
        EasyHttp.post(ShopUrl.SHOP_GIFT_DETAIL)
                .params("userGiftId", userGiftId + "")
                .params("phoneNum", CommonUtils.getInstance().getUserName())
                .params("siteId", CommonUtils.getInstance().getSite() + "")
                .execute(new SimpleCallBack<ShopGiftDetailBean>() {
                    @Override
                    public void onError(ApiException e) {
                        mPresenter.setError("获取详情失败！");
                    }

                    @Override
                    public void onSuccess(ShopGiftDetailBean bean) {
                        mPresenter.setDetail(bean);
                    }
                });
    }

    @Override
    public void pay(int userGiftId, String phoneNum, String sign, int payType) {
        EasyHttp.post(ShopUrl.SHOP_GIFT_PAY)
                .params("phoneNum", CommonUtils.getInstance().getUserName())
                .params("siteId", CommonUtils.getInstance().getSite() + "")
                .params("userGiftId", userGiftId + "")
                .params("sign", sign)
                .params("payType",payType+"")
                .execute(new SimpleCallBack<ShopPayResultBean>() {
                    @Override
                    public void onError(ApiException e) {
                        mPresenter.payError(e.getMessage());
                    }

                    @Override
                    public void onSuccess(ShopPayResultBean bean) {
                        mPresenter.paySuccess(bean);
                    }
                });
    }
}
